package
{
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.MouseEvent;

public class ArcTool extends MoveTool
{
	protected var arc_handler:Boolean;
	protected var focusArc:Arc;
	protected var focusPoint:Object;
	protected var dx:Number;
	protected var dy:Number;
	protected var resetting:Boolean;
	
	public function ArcTool()
	{
		super();
		this.keyCode=65;
	}
	
	override public function upAddPointAction():void{
		addPoint.id=canvas.getNewId();
		targetLine.splitPath(addPoint);
		
		//add the point, then make it a arc, and add arc to arc collection
		canvas.addArc(addPoint);
	}
	
	override public function drawSelectedPoint(point:Object,point_pen:Graphics,mouse_mc:Sprite):void{
		if(!point.isArc)return;
		//is selected
		super.drawSelectedPoint(point,point_pen,mouse_mc);
		arc_handler=true;
		
		//draw handler for rect setting
		var handler:Sprite=new Sprite();
		handler.graphics.lineStyle(0,0x0066cc,0);
		handler.graphics.beginFill(0x0066cc,1);
		handler.graphics.drawCircle(0,0,5);
		handler.graphics.endFill();
		
		focusArc=canvas.getArc(point);
		
		var corner:Array=canvas.getCorner(point);
		var p1:Object=canvas.data[corner[1]];
		var p2:Object=canvas.data[corner[2]];
		
		var dx1:Number=Math.abs(p1.x-p2.x);
		var dy1:Number=Math.abs(p1.y-p2.y);
		
		if(dx1<dy1){
			handler.x=point.x-focusArc.r;
			handler.y=point.y;
		}else{
			handler.x=point.x;
			handler.y=point.y+focusArc.r;
		}
		
		dx=dx1;
		dy=dy1;
		
		focusPoint=point;
		
		handler.addEventListener(MouseEvent.MOUSE_DOWN,downHandler);
	
		mouse_mc.addChild(handler);
	
	}
	
	public function upHandler(evt:MouseEvent):void{
		caughtDown=false;
		resetting=false;
		canvas.stage.removeEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
		canvas.stage.removeEventListener(MouseEvent.MOUSE_UP,upHandler);
	}
	
	public function downHandler(evt:MouseEvent):void{
		caughtDown=true;
		resetting=true;
		canvas.stage.addEventListener(MouseEvent.MOUSE_MOVE,moveHandler);
		canvas.stage.addEventListener(MouseEvent.MOUSE_UP,upHandler);
	}
	public function moveHandler(evt:MouseEvent):void{
		var p:Object=canvas.simpleMousePoint();
	
		if(dx<dy){
			focusArc.r=focusPoint.x-p.x;
		}else{
			focusArc.r=p.y-focusPoint.y;
		}
	}
	override public function directUpHandler(target:Object):void{
		trace("target"+target.isArc);
		
		if(target.isArc){
			var arc:Arc=canvas.getArc(target);
			arc.flipArc();
		}
		
	}
	
	
	
}

}

